package com.example.myui.activity;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.example.myui.R;
import com.example.myui.customview.MyCircle;
import com.example.myui.widget.NumberProgres;

public class CustomActivity extends AppCompatActivity {

    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler();
    private NumberProgres numpb;
    private MyCircle circle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_custom);

        circle = findViewById(R.id.mycircle);


        numpb = findViewById(R.id.numpb);
        numpb.setProgress(0);
        numpb.setReachedBarColor(Color.RED);
        numpb.setUnreachedBarColor(Color.BLACK);
        mHandler.postDelayed(runnable, 1000);
    }

    private String TAG = CustomActivity.class.getSimpleName();
    private int progress = 0;
    private int sweepAngle = 0;
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
//            if (progress <= 100) {
//                progress = progress + 1;
//                numpb.setProgress(progress);
//                mHandler.postDelayed(this, 100);
//                Log.i(TAG, "run: " + progress);
//            } else {
//                Toast.makeText(CustomActivity.this, "finished", Toast.LENGTH_SHORT).show();
//            }

            if (circle.getSweepAngle() <= 360) {
                sweepAngle++;
                circle.setSweepAngle(sweepAngle);
                mHandler.postDelayed(this, 100);
            } else {
                mHandler.removeCallbacks(this);
            }


        }
    };

}
